﻿using WeChat.CMS.Localization;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Localization;
using WeChat.CMS.AuditLogging;
using Volo.Abp.Identity;
using WeChat.CMS.Volo.Identity;
using Volo.Abp.AuditLogging.Localization;
using Volo.Abp.Identity.Localization;
using WeChat.CMS.WeChatManagers;

using WeChat.CMS.Businesses;

namespace WeChat.CMS.Permissions;

public class CMSPermissionDefinitionProvider : PermissionDefinitionProvider
{
    public override void Define(IPermissionDefinitionContext context)
    {
        var identityGroup = context.GetGroup(IdentityPermissions.GroupName);

        var ouPermission = identityGroup.AddPermission(CMSIdentityPermissions.OrganitaionUnits.Default, IdentityL("Permission:OrganitaionUnitManagement"));
        ouPermission.AddChild(CMSIdentityPermissions.OrganitaionUnits.CreateRootOrg, IdentityL("Permission:CreateRootOrg"));//添加根组织
        ouPermission.AddChild(CMSIdentityPermissions.OrganitaionUnits.CreateSubOrg, IdentityL("Permission:CreateSubOrg"));//添加子组织
        ouPermission.AddChild(CMSIdentityPermissions.OrganitaionUnits.Update, IdentityL("Permission:Edit"));//修改组织
        ouPermission.AddChild(CMSIdentityPermissions.OrganitaionUnits.Delete, IdentityL("Permission:Delete"));
        ouPermission.AddChild(CMSIdentityPermissions.OrganitaionUnits.AddUseToOrganization, IdentityL("Permission:AddUseToOrganization"));
        ouPermission.AddChild(CMSIdentityPermissions.OrganitaionUnits.DeleteUseFromOrganization, IdentityL("Permission:DeleteUseFromOrganization"));


        var aduditLogPermission = identityGroup.AddPermission(AuditLogPermissions.AuditLogs.Default, AuditLoggingL("审计日志"));
        aduditLogPermission.AddChild(AuditLogPermissions.AuditLogs.Delete, AuditLoggingL("删除"));


        var wechatManagementGroup = context.AddGroup(WechagManagementPermissions.GroupName,L("微信管理"));
        //Define your own permissions here. Example:
        var wechatManagmentPermission = wechatManagementGroup.AddPermission(WechagManagementPermissions.WechatConfig.Default, L("微信配置管理"));
        //wechatManagmentPermission.AddChild(CMSPermissions.WeChatUserGroupName, L("Permission:MyPermission1"));


        //var foodGroup = context.AddGroup(FoodPermissions.GroupName);
        //var foodPermission = foodGroup.AddPermission(FoodPermissions.Foods.Default);

        var businessGroup = context.AddGroup(BusinessPermissions.GroupName,L("业务管理"));
        var foodPermission = businessGroup.AddPermission(BusinessPermissions.Foods.Default, L("菜品管理"));
        var addFoodPer= foodPermission.AddChild(BusinessPermissions.Foods.Add, L("菜品添加"));
        foodPermission.AddChild(BusinessPermissions.Foods.Update ,L("菜品修改"));
        foodPermission.AddChild(BusinessPermissions.Foods.Delete, L("菜品删除"));
        addFoodPer.AddChild(BusinessPermissions.Foods.Add_1,L("子项测试"));


    }

    private static LocalizableString L(string name)
    {
        return LocalizableString.Create<CMSResource>(name);
    }

    private static LocalizableString IdentityL(string name)
    {
        return LocalizableString.Create<IdentityResource>(name);
    }

    private static LocalizableString AuditLoggingL(string name)
    {
        return LocalizableString.Create<AuditLoggingResource>(name);
    }
}
